<?php

class SettingController extends Controller
{
	public $layout='//layouts/empty';
	public function actionIndex()
	{
		$this->render('index');
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
	//修改用户基本信息；
	public function actionSetPersonal()
	{
		$vo = Userdetail::model()->findByPk(Yii::app()->user->id);
        $message = null;
		if ($_POST) 
		{
			$Userdetail=new Userdetail();
			//$userdetail->attributes->UID = $vo['UID'];
			$Userdetail->attributes = $_POST;
			if ($Userdetail->validate()) 
			{
				if ($vo!==null) {
					$vo->Sex = $_POST['Sex'];
					$vo->Address = $_POST['province'].','.$_POST['city'].','.$_POST['county'];
					$vo->Birthday = $_POST['Birthday'];
					$vo->Tel = $_POST['Tel'];
					$vo->Profession = $_POST['Profession'];
					$message = ($vo->update())?'更新成功':'更新失败';
				}else {
					$userdetail->save();
					$message = '插入成功';
				}
			}else
			{
				$message = $Userdetail->getErrors();
			}
			
			$this->render('setPersonal',array('vo'=>$vo->attributes,'message' => $message));
		}else{
			$this->render('setPersonal',array('vo'=>$vo->attributes,'message' => $message));
		}
		
	}
	//修改用户密码；
	public function actionSetPassword()
	{
		
		if ($_POST) 
		{
			$vo = User::model()->findByPk(Yii::app()->user->ID);
			if ($vo->Password != md5($_POST['current_password']))
			{
				echo '旧密码不正确';
			}else
			{
				if (($_POST['new_password']) !== ($_POST['confirm_password'])) {
					echo '两次密码不一致，请重新输入';
				}else 
				{
					$vo->Password = md5($_POST['new_password']);
					$result = $vo->update();
					if ($result) 
					{
						echo '修改密码成功';
					}else 
					{
						echo '修改密码失败';
					}
				}
			}
			$this->render('setPassword');
		}else
		{
			$this->render('setPassword');
		}
		
	}
	public function actionList(){
		$this->render('field');
		
	}
}